package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.bairong.BairongUserCustomizeCreditScore3Data;
import com.ucredit.babel.common.model.third.bairong.BairongUserCustomizeCreditScore3Record;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/*
 * 百融渠道评分 A
 *
 * @author:szw
 * */

public class BaiRongUserCustomizeCreditScore3Parse extends ParseBase{
    private Text val = new Text();
    private Text key = new Text();

    /**
     * @param context
     * @param model
     * @param successful
     * @return
     * @throws IOException
     * @throws InterruptedException
     */

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BairongUserCustomizeCreditScore3Record brRecord = (BairongUserCustomizeCreditScore3Record) model;
        BairongUserCustomizeCreditScore3Data brData = brRecord.getData();

        StringBuilder sb = getBaseInfo(brRecord, successful);
        StringBuilder brSb = new StringBuilder(2000);

        brSb.append(brData.getCode() == null ? "" : brData.getCode()).append(CRT001);
        brSb.append(brData.getSwiftNumber() == null ? "" : brData.getSwiftNumber()).append(CRT001);
        brSb.append(brData.getFlag().getScore() == null ? "" : brData.getFlag().getScore()).append(CRT001);
        brSb.append(brData.getScore().getScorecust3() == null ? "" : brData.getScore().getScorecust3()).append(CRT001);
        StringBuilder txSb = getBaseInfo(brRecord);
        key.set(getKey());
        val.set((sb.toString() + brSb.toString() + txSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);

        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_br_user_customize_credit_score3_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIRONG_USER_CUSTOMIZE_CREDIT_SCORE3_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百融渠道评分 A";
    }
}
